<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>字符串编码</title>
</head>
<body>
<script>
    // let str = 'AACBBEEFFDDAA';
    let str = 'A';

    function changeStr(str) {
        let initStr = str[0], counter = 1;
        let result = '';
        for (let i = 1; i < str.length + 1; i++) {
            if (initStr === str[i]) {
                counter++;
            } else {
                result += counter + initStr;
                initStr = str[i];
                counter = 1;
            }
        }
        return result;
    }
    console.log(changeStr(str));
</script>
</body>
</html>